#include"comm.hpp"
#include"log.hpp"

using namespace std;

//管理管道文件
int main()
{
    //log.hpp的程序：日志
    // logmessage(Debug,"hello");

    //comm.hpp的程序：命名管道
    Init init;
    Log log;
    //log.Enable(Onefile);    //往一个文件中去打印
    log.Enable(Classfile);  //往分类文件中去打印

    //打开管道
    int fd =open(FIFO_FILE,O_RDONLY);        //读端打开文件之后，写端才会打开文件
    if(fd<0)
    {
        log(Fatal,"error string:%s , error code: %d",strerror(errno),errno);
        exit(FIFO_OPEN_ERR);
    }
    // cout<<"server open file success"<<endl;

    log(Info,"server open file success,error string:%s , error code: %d",strerror(errno),errno); //日志
    //开始通信s
    while(true)
    {
        char buffer[1024]={0};
        int x=read(fd,buffer,sizeof(buffer));
        if(x>0)
        {
            buffer[x]=0;
            cout<<"client say: "<<buffer<<endl;
        }
        else if(x==0)
        {
            log(Debug,"Client quit,me too error string:%s , error code: %d",strerror(errno),errno); //日志
            break;
        }
        else break;
    }
    close(fd);

    
    return 0;
}